package com.demo.simpletestapp.utils

import android.content.Context
import kotlin.properties.Delegates

object DensityUtils {
    /**
     * 不同density
     * 1F-默认是375_1倍
     * 1-400
     * 【后面需要再添加】
     */
    private var typeDensity: Float = 1F
    private var mContext by Delegates.notNull<Context>()

    /**
     * 设置获取到的dp值的倍率
     */
    fun getDensity(context: Context) {
        mContext = context
        val densityDpi = context.resources.displayMetrics.densityDpi
        typeDensity = when(densityDpi){
            400-> 0.5F
            else -> 1F
        }
    }

    /**
     * 通过这个方法获取的dp值是经过倍率计算的
     * @param dimenRes 例如：R.dimen.dp_18
     */
    fun getDimension(dimenRes: Int):Float{
        val dimension = mContext.resources.getDimension(dimenRes)
        return dimension * typeDensity
    }

//    fun showh(context: Context) {
//        val metrics = context.resources.displayMetrics
//        val density = metrics.densityDpi
//        val densityString: String
//        densityString = if (density <= DisplayMetrics.DENSITY_MEDIUM) {
//            "mdpi"
//        } else if (density <= DisplayMetrics.DENSITY_HIGH) {
//            "hdpi"
//        } else if (density <= DisplayMetrics.DENSITY_XHIGH) {
//            "xhdpi"
//        } else if (density <= DisplayMetrics.DENSITY_XXHIGH) {
//            "xxhdpi"
//        } else if (density <= DisplayMetrics.DENSITY_XXXHIGH) {
//            "xxxhdpi"
//        } else {
//            "Unknown density"
//        }
//        Log.d("Density Info", "Device density: $densityString")
//    }

}